<template>
  <div class="app-container">
    <el-row>
      <el-col :span="5" :xs="24">
		<div style="width: 100%;height:600px;overflow:hidden;">
        <el-tree
            style="width: 106%; height:100%;overflow:auto;overflow-x:hidden;"
            node-key="id"
            :default-expanded-keys="[1]"
            :data="deptOptions"
            :expand-on-click-node="false"
            ref="tree"
            @node-click="handleNodeClick">
            <!--过长处理，鼠标悬浮文字弹框显示全部内容-->
            <span slot-scope="{ node }">
              <el-tooltip class="item" effect="light" :content="node.label" placement="top-start"
                v-if="node.label.length>12">
                <span> {{ node.label | ellipsis(12) }} </span>
              </el-tooltip>
              <span v-if="node.label.length<=12">{{node.label}}</span>
            </span>
          </el-tree>
		  </div>
      </el-col>
      <el-col :span="19" :xs="24">
        <el-form :model="queryParams" ref="queryForm" :inline="true" style="margin:0px 20px;">
          <el-form-item label="实验室" prop="labId">
            <el-select
              size="mini"
              clearable
              v-model="queryParams.labId"
              placeholder="请选择实验室">
              <el-option v-for="item in collegeLabList" :key="item.orgName" :label="item.orgName"
                :value="item.orgId">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="专业" prop="majorOpt">
            <el-select
              size="mini"
              clearable
              v-model="queryParams.majorOpt"
              placeholder="请选择专业">
              <el-option
                v-for="dict in majorOptOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="parseInt(dict.dictValue)"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="星期" prop="weekDayOpt">
            <el-select
              size="mini"
              clearable
              v-model="queryParams.weekDayOpt"
              placeholder="请选择星期">
              <el-option
                v-for="dict in weekDayOptOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="parseInt(dict.dictValue)"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['course:course:edit']"
            >新增</el-button>
            <el-button
              type="warning"
              icon="el-icon-upload"
              size="mini"
              @click="handleImport"
              v-hasPermi="['course:course:import']"
            >导入</el-button>
          </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="courseList">
          <el-table-column label="序号" align="center" type="index" />
          <el-table-column label="学院"  width="150px" show-overflow-tooltip prop="collegeOrgId" :formatter="collegeOrgIdFormat" />
          <el-table-column label="实验室"  width="150px" show-overflow-tooltip prop="labId" :formatter="labIdFormat" />
          <el-table-column label="专业" align="center" width="150px" show-overflow-tooltip prop="majorOpt" :formatter="majorOptFormat"/>
          <el-table-column label="课程编码" align="center" prop="courseNo" />
          <el-table-column label="课程名称" align="center" width="100px" show-overflow-tooltip prop="courseName" />
          <el-table-column label="实验学时" align="center" prop="experimentalHours" />
          <el-table-column label="人数" align="center" prop="personNum" />
          <el-table-column label="周次" align="center" width="60" prop="weekOpenNums" />
          <el-table-column label="周一" align="center" prop="day1" width="60"/>
          <el-table-column label="周二" align="center" prop="day2" width="60"/>
          <el-table-column label="周三" align="center" prop="day3" width="60"/>
          <el-table-column label="周四" align="center" prop="day4" width="60"/>
          <el-table-column label="周五" align="center" prop="day5" width="60"/>
          <el-table-column label="周六" align="center" prop="day6" width="60"/>
          <el-table-column label="周日" align="center" prop="day7" width="60"/>
          <el-table-column label="操作" align="center" width="100px" class-name="small-padding fixed-width" v-if="isPermit('course:course:edit')">
            <template slot-scope="scope">
             <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['course:course:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row,scope.$index)"
              >取消</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>

    <!-- 添加或修改课程管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="750px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="学院" prop="collegeOrgId">
              <el-select
                class="input_w"
                v-model="form.collegeOrgId"
                placeholder="请选择学院"
                @change="handleCollegeChange">
                <el-option v-for="item in collegeList" :key="item.orgName" :label="item.orgName" :value="item.orgId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="专业" prop="majorOpt">
              <el-select
                class="input_w"
                v-model="form.majorOpt"
                placeholder="请选择专业">
                <el-option
                  v-for="dict in majorOptOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="实验室" prop="labId">
              <el-select
                class="input_w"
                v-model="form.labId"
                placeholder="请选择实验室">
                <el-option v-for="item in labList" :key="item.orgName" :label="item.orgName"
                  :value="item.orgId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开课地点" prop="classRoomId">
              <el-input class="input_w" v-model="form.classRoomId" placeholder="请输入开课地点" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="课程编码" prop="courseNo">
              <el-input class="input_w" v-model="form.courseNo" placeholder="请输入课程编码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="课程名称" prop="courseName">
              <el-input class="input_w" v-model="form.courseName" placeholder="请输入课程名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="实验项目" prop="experimentalProject">
              <el-input class="input_w" v-model="form.experimentalProject" placeholder="请输入实验项目" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实验学时" prop="experimentalHours">
              <el-input class="input_w" type="number" min="1" v-model="form.experimentalHours" placeholder="请输入实验学时" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="班级" prop="classNo">
              <el-input class="input_w" v-model="form.classNo" placeholder="请输入班级" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="人数" prop="personNum">
              <el-input class="input_w" type="number" min="1" v-model="form.personNum" placeholder="请输入人数" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="每组人数" prop="personsOfGroup">
              <el-input type="number" min="1" v-model="form.personsOfGroup" placeholder="每组人数"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="周次">
              <el-input type="number" min="1" v-model="form.weekOpenNums" placeholder="周次"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="周一">
              <el-row>
                <el-col :span="12">
                  <el-form-item prop="day1" style="width: 122px;">
                    <el-input type="number" min="1" v-model="form.day11" placeholder="节次开始"/>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="day1" style="width: 122px;">
                    <el-input type="number" min="1" v-model="form.day12" placeholder="节次结束"/>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="周二">
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="day2" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.day21" placeholder="节次开始"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="day2" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.day22" placeholder="节次结束"/>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="周三">
              <el-row>
                <el-col :span="12">
                  <el-form-item prop="day3" style="width: 122px;">
                    <el-input type="number" min="1" v-model="form.day31" placeholder="节次开始"/>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="day3" style="width: 122px;">
                    <el-input type="number" min="1" v-model="form.day32" placeholder="节次结束"/>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="周四">
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="day4" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.day41" placeholder="节次开始"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="day4" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.day42" placeholder="节次结束"/>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="周五">
              <el-row>
                <el-col :span="12">
                  <el-form-item prop="day5" style="width: 122px;">
                    <el-input type="number" min="1" v-model="form.day51" placeholder="节次开始"/>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="day5" style="width: 122px;">
                    <el-input type="number" min="1" v-model="form.day52" placeholder="节次结束"/>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="周六">
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="day6" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.day61" placeholder="节次开始"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="day6" style="width: 122px;">
                      <el-input type="number" min="1" v-model="form.day62" placeholder="节次结束"/>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="周日">
              <el-row>
                <el-col :span="12">
                  <el-form-item prop="day7" style="width: 122px;">
                    <el-input type="number" min="1" v-model="form.day71" placeholder="节次开始"/>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item prop="day7" style="width: 122px;">
                    <el-input type="number" min="1" v-model="form.day72" placeholder="节次结束"/>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-for="(teacher, index) in form.courseTeacherList" :key="index">
          <el-col :span="12">
            <el-form-item label="老师工号"
            :prop="'courseTeacherList.' + index + '.teacherNo'"
            :rules="{
              required: true, message: '老师工号不能为空', trigger: 'blur'
            }">
              <el-input v-model="teacher.teacherNo" @blur="searchUser(index)"
                @keyup.enter.native="searchUser(index)" placeholder="请输老师工号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="老师姓名"
            :prop="'courseTeacherList.' + index + '.teacherName'"
            :rules="{
              required: true, message: '老师姓名不能为空', trigger: 'blur'
            }">
              <el-input v-model="teacher.teacherName" disabled placeholder="请输老师姓名" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :offset="1">
            <el-button @click="addTeacher">新增代课老师</el-button>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <CreateDialog ref="createDialog" @refresh="getList"></CreateDialog>
    <SelectCourse @setCourse="setCourse" ref="selectCourse"></SelectCourse>
    
    <el-dialog title="课程导入" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :action="upload.url"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :disabled="upload.isUploading"
        :auto-upload="false"
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { searchEmployee } from "@/api/labdata/employee";
import { treeselect, getTreeLabel } from "@/api/labdata/orgnization";
import { getOrgByFunctionOpt, listSecondOrgLab, listOrgnization } from "@/api/labdata/orgnization";
import { listCourse, getCourse, delCourse, addCourse, updateCourse, exportCourse, delCourseDate, importTemplate } from "@/api/course/course";
import CreateDialog from "@/views/course/adjust/createDialog.vue";
import SelectCourse from '@/views/course/course/select_course.vue'

export default {
  name: "Course",
  components: {
    CreateDialog, SelectCourse
  },
  data() {
    return {
      // 课程导入参数
      upload: {
        open: false,
        isUploading: false,
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/course/course/importData"
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 课程管理表格数据
      courseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 课程时间表ID
      timetableId: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        timetableId: null,
        collegeOrgId: null,
        labId: null,
        majorOpt: null,
        weekDayOpt: null
      },
      deptOptions: [],
      weekFlagOptions:[],
      weekDayOptOptions: [],
      majorOptOptions: [],
      // 表单参数
      form: {
        courseTeacherList: [{
          teacherNo: null,
          teacherName: null
        }],
      },
      collegeLabList: [],
      orgnizationList: [],
      collegeList: [],
      labList: [],
      // 表单校验
      rules: {
        collegeOrgId: [
          { required: true, message: "学院不能为空", trigger: "blur" }
        ],
        labId: [
          { required: true, message: "实验室不能为空", trigger: "blur" }
        ],
        majorOpt: [
          { required: true, message: "专业不能为空", trigger: "blur" }
        ],
        courseNo: [
          { required: true, message: "课程编码不能为空", trigger: "blur" }
        ],
        experimentalProject: [
          { required: true, message: "实验项目不能为空", trigger: "blur" }
        ],
        classNo: [
          { required: true, message: "班级不能为空", trigger: "blur" }
        ],
        classRoomId: [
          { required: true, message: "开课地点不能为空", trigger: "blur" }
        ],
        courseName: [
          { required: true, message: "课程名称不能为空", trigger: "blur" }
        ],
        personNum: [
          { required: true, message: "人数不能为空", trigger: "blur" }
        ],
        weekOpenNums: [
           { required: true, message: "周次不能为空", trigger: "blur" }
        ],

      }
    };
  },
  created() {
    // 学院
    this.getCollegeList()
    // 所有学院机构
    this.getOrgnizations()
    // 星期
  /*  this.getDicts("weekDayOpt").then(response => {
        this.weekDayOptOptions = response.data;
    }); */
    this.getDicts("majorOpt").then(response => {
        this.majorOptOptions = response.data;
    });
   /* this.getDicts("weekFlagOpt").then(response => {
        this.weekFlagOptions = response.data;
    }); */

  },
  beforeRouteEnter(to, from, next) {
    const timetableId = to.query.id
    next(vm => {
      vm.timetableId = timetableId
      vm.getTreeselect()
      vm.getList()
    })
  },
  methods: {
    importTemplate() {
      // importTemplate()
      // this.download('course/course/importTemplate', {
      // }, `course_template_${new Date().getTime()}.xlsx`)
      window.open(process.env.VUE_APP_BASE_API + "/course/course/importTemplate")
    },
    handleImport() {
      this.upload.open = true
    },
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
   /* weekFlagFormat(row, column) {
      return this.selectDictLabel(this.weekFlagOptions, row.weekFlag);
    }, */
    getOrgnizations() {
      listOrgnization({}).then(response => {
        this.orgnizationList = response.rows
      });
    },
    collegeOrgIdFormat(row, column) {
      let obj = this.orgnizationList.find(item => item.orgId == row.collegeOrgId)
      if (obj) {
        return obj.orgName
      }
      return ''
    },
    labIdFormat(row, column) {
      let obj = this.orgnizationList.find(item => item.orgId == row.labId)
      if (obj) {
        return obj.orgName
      }
      return ''
    },
   /* weekDayOptFormatter(row, column) {
      let obj = this.weekDayOptOptions.find(item => item.dictValue == row.weekDayOpt)
      if (obj) {
        return obj.dictLabel
      }
      return ''
    }, */
   /* sectionFormatter(row, column) {
      if(!row.sectionStart){
        return "";
      }
      return row.sectionStart + '-' + row.sectionEnd + '节'
    }, */
    searchUser(index) {
      const courseTeacher = this.form.courseTeacherList[index]
      if (!courseTeacher.teacherNo) {
        courseTeacher.teacherNo = null
        courseTeacher.teacherName = null
        return;
      }
      searchEmployee(courseTeacher.teacherNo).then(response => {
        let searchResult = response.data
        if (searchResult) {
          courseTeacher.teacherNo = searchResult.employeeNo
          courseTeacher.teacherName = searchResult.nickName
        } else {
          courseTeacher.teacherNo = null
          courseTeacher.teacherName = null
        }
      });
    },
    getCollegeList(){
      getOrgByFunctionOpt(2).then(response => {
        this.collegeList = response.data
      });
    },
    handleCollegeChange(item) {
      this.form.labId = null
      if (item) {
        this.getLabList(item)
      }
    },
    getLabList(id) {
      listSecondOrgLab(id).then(response => {
        this.labList = response.data
      });
    },
    addTeacher() {
      this.form.courseTeacherList.push({
        teacherNo: null,
        teacherName: null
      })
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.resetForm("queryForm");
      this.queryParams.collegeOrgId = data.id
      this.getList()
      listSecondOrgLab(data.id).then(response => {
        this.collegeLabList = response.data
      });
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        let deptOptions = response.data;
        for (let item of deptOptions[0].children) {
          item.children = []
        }
        this.deptOptions = deptOptions
      });
    },
    getTreeNodeLabel(deptId){
      return getTreeLabel(this.deptOptions, deptId);
    },
    /** 查询课程管理列表 */
    getList() {
      this.loading = true;
      this.queryParams.timetableId = this.timetableId
      listCourse(this.queryParams).then(response => {
        this.courseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        courseId: null,
        collegeOrgId: null,
        labId: null,
        majorOpt: null,
        courseNo: null,
        experimentalProject: null,
        classNo: null,
        personsOfGroup: null,
        weekDayOpt: null,
        classRoomId: null,
        courseName: null,
        experimentalHours: null,
        personNum: null,
        weekOpenNums: null,
        sectionStart: null,
        sectionEnd: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        courseTeacherList: [{
          teacherNo: null,
          teacherName: null
        }]
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.courseId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "新增课程";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const courseId = row.courseId || this.ids
      getCourse(courseId).then(response => {
        this.form = response.data;
        for(var i=1;i<=7;i++){
          if(this.form['day'+i]){
            let arr = this.form['day'+i].split("-");
            this.form['day'+i+'1']= arr[0];
            this.form['day'+i+'2'] = arr[1];
          }
        }
        this.getLabList(this.form.collegeOrgId)
        this.open = true;
        this.title = "修改课程";
      });
    },
    handleAdjust(row) {
      this.$refs["createDialog"].handleAdd(row.courseDateId);
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if(this.form.day11 && this.form.day12){
             if(this.form.day11 >= this.form.day12){
                this.msgError("周一起始节点必须小于结束节点");
                return;
             }
             this.form.day1 = this.form.day11 + '-' + this.form.day12;
          }
         if(this.form.day21 && this.form.day22){
           if(this.form.day21 >= this.form.day22){
              this.msgError("周二起始节点必须小于结束节点");
              return;
            }
            this.form.day2 = this.form.day21 + '-' + this.form.day22;
         }
         if(this.form.day31 && this.form.day32){
           if(this.form.day31 >= this.form.day32){
              this.msgError("周三起始节点必须小于结束节点");
              return;
           }
             this.form.day3 = this.form.day31 + '-' + this.form.day32;
         }
         if(this.form.day41 && this.form.day42){
           if(this.form.day41 >= this.form.day42){
              this.msgError("周四起始节点必须小于结束节点");
              return;
           }
            this.form.day4 = this.form.day41 + '-' + this.form.day42;
         }
         if(this.form.day51 && this.form.day52){
           if(this.form.day51 >= this.form.day52){
              this.msgError("周五起始节点必须小于结束节点");
              return;
           }
             this.form.day5 = this.form.day51 + '-' + this.form.day52;
         }
         if(this.form.day61 && this.form.day62){
           if(this.form.day61 >= this.form.day62){
              this.msgError("周六起始节点必须小于结束节点");
              return;
           }
            this.form.day6 = this.form.day61 + '-' + this.form.day62;
         }
         if(this.form.day71 && this.form.day72){
           if(this.form.day71 >= this.form.day72){
              this.msgError("周日起始节点必须小于结束节点");
              return;
           }
           this.form.day7 = this.form.day71 + '-' + this.form.day72;
         }
          this.form.timetableId = this.timetableId
          if (this.form.courseId != null) {
            updateCourse(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCourse(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleCourseDelete() {
      this.$refs['selectCourse'].handleShow()
    },
    setCourse(id) {
      this.$confirm('是否确认删除课程管理id为"' + id + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delCourse(id);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 删除按钮操作 */
    handleDelete(row, index) {
      const courseId = row.courseId
      this.$confirm('是否确认删除序号为"' + (index+1) + '"的课表数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delCourse(courseId);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    isPermit(permitKey){
      if(this.$store.state.user.name=='admin'){
        return true;
      }
      let  permissions = this.$store.getters.permissions;
      return permissions.includes(permitKey);
    },
    majorOptFormat(row, column) {
      let obj = this.majorOptOptions.find(item => item.dictValue == row.majorOpt)
      if (obj) {
        return obj.dictLabel
      }
      return ''
    }
  }
};
</script>


<style scoped>
  .input_w {
    width: 250px;
  }
  .line {
    width: 10px;
  }
</style>
